package com.easy.generator;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDate;

/**
 * @author easy
 * @date 2025年07月06日 05:25
 */
public class ApplicationGenerator {
    private static final String CLASS_NAME = "Application";
    private static final String PACKAGE_NAME = Easy.MODEL_PACKAGE;

    private static final String CLASS_TEMPLATE =
            "package "+PACKAGE_NAME+";\n" +
                    "\n" +
                    "import org.springframework.boot.SpringApplication;\n" +
                    "import org.springframework.boot.autoconfigure.SpringBootApplication;\n" +
                    "\n" +
                    "@SpringBootApplication\n" +
                    "public class "+CLASS_NAME+" {\n" +
                    "\n" +
                    "    public static void main(String[] args) {\n" +
                    "        SpringApplication.run("+CLASS_NAME+".class, args);\n" +
                    "    }\n" +
                    "}\n";
    public static void generateApplication() throws IOException {
        String content = String.format(CLASS_TEMPLATE, LocalDate.now());
        File outputFile = new File(Easy.PROJECT_ABSOLUTE_URL + Easy.SRC_DIR + Easy.convertPackagePath(PACKAGE_NAME) + "/" + CLASS_NAME + ".java");
        try (FileWriter writer = new FileWriter(outputFile)) {
            writer.write(content);
        }
    }
    public static void generate() throws IOException {
        Easy.initPackage(PACKAGE_NAME);
        generateApplication();
    }
}
